import axios from "axios";
import {env} from "../../env.js";
import { ElMessage, ElNotification } from 'element-plus'

const api = axios.create({
  baseURL:env.base_url,
  timeout: 5000,
  responseType:'json',
  withCredentials:'',
  headers:{
  }
})
// axios.interceptors.request.use(
// )
let result = {
  code:200,
  message:"",
  success:true,
  timestamp:"",
  data:""
}
// 响应拦截器
api.interceptors.response.use(
  function (response) {
    // closeLoading();
    result = response.data
    console.log("result",result)
    if (result.code===200){
      console.log("成功");
      // ElMessage({
      //     message: result.message,
      //     type: 'success',
      //     duration:2000
      // })
    }else{
      console.log("失败");
      ElNotification({
          title: 'Error',
          message: result.message,
          type: 'error',
      })

    }
    return result.data
  },function (error) {
    return Promise.reject(error)
  }
)
export default api;